package com.competition.front.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.competition.commonutils.R;
import com.competition.front.entity.CourseVideo;
import com.competition.front.entity.vo.QueryVo;
import com.competition.front.entity.vo.VideoInfo;
import com.competition.front.service.CourseVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-04-05
 */
@RestController
@RequestMapping("/front/course-video")
@CrossOrigin
@Api(description = "前台关于防控讲堂相关的接口")
public class CourseVideoController {

    @Autowired
    private CourseVideoService courseVideoService;
    @PostMapping("getCourseVideoList")
    @ApiOperation("讲堂查询加分页,key为管理员的用户名或者标题")
    public R getCourseVideoList(@RequestBody QueryVo queryVo){
        int videoInfoCount=courseVideoService.getCourseVideoCount(queryVo);
        List<VideoInfo> videoInfoList=courseVideoService.getCourseVideoList(queryVo);
        return R.ok().data("videoInfoList",videoInfoList).data("videoInfoCount",videoInfoCount);
    }

    @PostMapping("updateCourseVideoPlay/{id}")
    @ApiOperation("讲堂播放数量加1，根据id进行更改")
    public R updateCourseVideoPlay(@PathVariable String id){
        CourseVideo courseVideo = courseVideoService.getById(id);
        Long playCount = courseVideo.getPlayCount();
        playCount=playCount+1;
        courseVideo.setPlayCount(playCount);
        courseVideoService.updateById(courseVideo);
        return R.ok();
    }
}

